import { fileURLToPath, URL } from 'node:url';

import vue from '@vitejs/plugin-vue';
import vueJsx from '@vitejs/plugin-vue-jsx';
import { defineConfig } from 'vite';
// @ts-ignore
import eslint from 'vite-plugin-eslint';
import swc from 'vite-plugin-swc-transform';

const local = 'http://localhost/api/v1';

// https://vitejs.dev/config/
export default defineConfig({
  base: process.env.BASE_URL || '/',
  plugins: [
    swc({
      swcOptions: {
        jsc: {
          target: 'es2022',
          transform: {
            legacyDecorator: true,
            decoratorMetadata: true,
            useDefineForClassFields: false,
            react: {
              runtime: 'automatic',
              importSource: 'vue-jsx-runtime',
            },
          },
          externalHelpers: true,
        },
      },
    }),
    vue(),
    vueJsx(),
    eslint(),
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url)),
    },
  },
  server: {
    port: 8080,
    proxy: {
      '/api/lightcone': {
        target: local,
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api\/lightcone/, ''),
        bypass(req) {
          req.headers.Referer = local;
          req.headers.Origin = local;
        },
      },
    },
  },
});
